package mutilthread;

import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * Description: 信号量(Semaphore)
 * User: Li_yizYa
 * Date: 2025—04—08
 * Time: 18:00
 */
public class Demo27 {
    public static void main(String[] args) throws InterruptedException {
        // 可用资源的个数，计数器的初始值
        Semaphore semaphore = new Semaphore(3);
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
        semaphore.release();
        System.out.println("释放一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源");
    }
}
